package cn.yunhe.service;

import cn.yunhe.dao.HouseDao;
import cn.yunhe.pojo.House;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

public class HouseService {
    SqlSession session=null;
    HouseDao houseDao=null;

    /**
     * 初始化
     */
    public void initial(){
        session=SqlSessionFactoryUtil.getSqlSession();
        houseDao=session.getMapper(HouseDao.class);
    }

    /**
     * 销毁
     */
    public void destory(){
        if (session!=null){
            session.commit();
            session.close();
        }
    }

    /**
     * 插入
     * @param house
     * @return
     */
    public boolean insertHouse(House house){
        initial();
        boolean flag= houseDao.insertHouse(house);
        destory();
        return flag;
    }

    /**
     * 更新
     * @param house
     * @return
     */
    public boolean updateHouse(House house){
        initial();
        boolean flag= houseDao.updateHouse(house);
        destory();
        return flag;
    }

    /**
     * 删除
     * @param hid
     * @return
     */
    public boolean deleteHouse(int hid){
        initial();
        boolean flag= houseDao.deleteHouse(hid);
        destory();
        return flag;
    }


    public List<House> houseList(House house){
        initial();
        List<House>houseList=houseDao.houseList(house);
        destory();
        return  houseList;
    }
    public List<House> houseListByMap(Map<String,Object> map){
        initial();
        List<House>houseList=houseDao.houseListByMap(map);
        destory();
        return  houseList;
    }
    public int houseListByMap2TotalRecords(Map<String,Object> map){
        initial();
        int totalRecords=houseDao.houseListByMap2TotalRecords(map);
        destory();
        return  totalRecords;
    }

}
